<?php
/**
 * 原型模式
 *
 * 创建一个产品的复制(深拷贝)
 *
 */
//原型抽象类
abstract class AbstractPrototype{
	public function copy(){
		$serialize_obj = serialize($this);
		$clone_obj = unserialize($serialize_obj);
		return $clone_obj;
	}	
}

class ConcreteProtype extends AbstractPrototype{
	public $name;

	function __construct($name){
		$this->name = $name;
	}
}
echo "before_change ----\n";
$protype = new ConcreteProtype('bjm');
echo 'protype name ='.$protype->name."\n";
$clone_protype = $protype->copy();
echo 'clone name='.$protype->name."\n";
$clone_protype->name = 'aaa';
echo "after_change ----\n";
echo "protype name =".$protype->name."\n";
echo "clone name =".$clone_protype->name."\n";

